﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yu.Cms.Common;

namespace Yu.Cms.Web.UserCtrl.Admin
{
    public partial class Album : BaseCtrl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.OnStart();
            }
        }

        /// <summary>
        /// 开始
        /// </summary>
        protected void OnStart()
        {
            this.Pager.PageSize = 12;
            this.BindrptAlbum();

        }

        /// <summary>
        /// 绑定
        /// </summary>
        protected void BindrptAlbum()
        {
            int PageIndex = Pager.CurrentPageIndex;
            int PageSize = Pager.PageSize;
            int RecordCount = 0;
            rptAlbum.DataSource = bllalbumType.GetList(true, PageIndex, PageSize, out RecordCount);
            rptAlbum.DataBind();
            Pager.RecordCount = RecordCount;            
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            this.BindrptAlbum();
        }

        /// <summary>
        /// 绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptAlbum_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                
                HiddenField hlf = e.Item.FindControl("hlf") as HiddenField;
                int alBigID = Utils.StrToInt(hlf.Value, 0);
                if (alBigID == 0)
                {
                    return;
                }
                Image imgAlbum = e.Item.FindControl("imgAlbum") as Image;
                int alTopID= bllalbumType.GetModel(alBigID).alTopID;
                if (!bllalbum.isExistPhoto(alBigID) || alTopID == 0)
                {
                    imgAlbum.ImageUrl = @"~/Images/no_photo_s.png";
                }
                else
                {
                    imgAlbum.ImageUrl = this.GetTopPhoto(alTopID);
                }
                
            }

        }

        /// <summary>
        /// 获取照片路径
        /// </summary>
        /// <param name="alId"></param>
        /// <returns></returns>
        protected string GetTopPhoto(int alId)
        {
            Yu.Cms.Model.album fam = bllalbum.GetModel(alId);
            return fam.alPath;
        }
      
    }
}